/**
 * Demonstrates a range of Button options the framework offers out of the box
 */
Ext.define('cloud.view.order.UnOrder', {
    extend: 'Ext.Container',
    xtype: 'unorder',
    requires: ['Ext.List', 'Ext.TitleBar', 'Ext.field.Select', 'Ext.field.Search'],
    config: {
        layout: 'vbox',
        items: [
            {
                xtype: 'toolbar',
                ui: 'dark',
                docked: 'top',
                style: '-webkit-box-shadow:1px 1px 3px #ccc;' +
                    'margin-bottom:6px;background:#FFFFFF;',
                items: [
                    {
                        xtype: 'button',
                        text: '返回',
                        id: 'UnOrderTitlebar',
                        hidden: true,
                        handler: function () {
                            Ext.getCmp('UnOrderID').setHidden(false);
                            Ext.getCmp('UnOrderSeachID').setHidden(true);
                            Ext.getCmp('UnOrderTitlebar').setHidden(true);
                            Ext.getCmp('search_unorder').setValue('');
                        }
                    },
                    {
                        xtype: 'textfield',
                        id: 'search_unorder',
                        width:'300px',
                        placeHolder: '请输入姓名/\手机/\订单号'
                    },
                    {
                        xtype:'button',
                        text:'打印订单',
                        id:'unorder_print'
                    }
                ]
            },
            {
                html:'<table class="tabclass tabclassHtml" >' +
                    '<tr>' +
                    '<td style="max-width: 20px;"><input type="checkbox" name="allcheck" id="allcheck" />全选</td>' +
                    '<td>姓名</td>' +
                    '<td>电话</td>' +
                    '<td>时间( 定 / 送 )</td>' +
                    '<td>地址</td>' +
                    '<td>品种</td>' +
                    '<td>总价</td>' +
                    '<td>支付方式</td>' +
                    '<td style="min-width:120px;">操作</td>' +
                    '</tr>' +
                    '</table>',
                listeners: {
                    painted: function (label) {
                        label.on('tap', function (target, event) {
                            if(!Ext.getCmp('UnOrderID').getHidden()){
                                var input = document.getElementsByName('record');
                            }else{
                                var input = document.getElementsByName('search_record');
                            }
                            if(target.target.name=='allcheck'){
                                for(i=0;i<input.length;i++)
                                {
                                    if(!event.checked){
                                        input[i].checked=true
                                    }else{
                                        input[i].checked=false
                                    }
                                }
                            }
                            return false;
                        }, this);
                    }
                }
            },
            {
                xtype: 'list',
                store: 'UnOrder',
                id: 'UnOrderID',
                emptyText: '木有数据',
                flex: 1,
                pressedCls:false,
                selectedCls:false,
                cls: 'x-list3',
                itemTpl: '<table class="tabclass">' +
                    '<tr>' +
                    '<td style="max-width: 20px;"><input type="checkbox" name="record" value="{coid}" /></td>' +
                    '<td>{consignee}</td>' +
                    '<td>{otel}</td>' +
                    '<td>{[Ext.Date.format(new Date(parseInt(values.createtime) * 1000), "Y-m-d H:i")]}<br>{takedate} {[values.taketime.substr(0,5)]}</td>' +
                    '<td>{takeaddress}</td>' +
                    '<td><tpl for="products">{pname} / {sname}<br></tpl></td>' +
                    '<td>{totalmoney} ￥</td>' +
                    '<td>{paymenttype}<tpl if="paymenttype!=\'货到付款\' ">({paymentstatus})</tpl></td>' +
                    '<td style="min-width:120px;"><input type="button" value="详情" name="detail" /> &nbsp;&nbsp;<input type="button" value="处理" name="passorder" /></td>' +
                    '</tr>' +
                    '</table>',
                listeners: {
                    painted: function () {
                        // if (Ext.getStore('UnOrder').getData().length == 0) {
                            Ext.getStore('UnOrder').getProxy().setExtraParams({'cadid':localStorage.getItem('cadid'),'param':'未处理'});
                            Ext.getStore('UnOrder').loadPage(1);
                        // }
                        // Ext.getStore('UnOrder').clearFilter();
                    }
                },
                plugins: [
                    {
                        xclass: 'Ext.plugin.PullRefresh',
                        pullRefreshText: '下拉可以更新',
                        releaseRefreshText: '松开开始更新',
                        style: 'top:12px',
                        loadingText: '正在刷新……',
                        refreshFn: function (loaded, arguments) {
                            loaded.getList().getStore().loadPage(1, {
                                callback: function (record, operation, success) {
                                    Ext.Viewport.unmask();
                                }, scope: this });
                        }
                    },
                    {
                        xclass: 'Ext.plugin.ListPaging',
                        loadMoreText: '<h2 style="text-align: center; padding-top: 20px; padding-bottom: 20px;">点击加载更多。。。。</h2>',
                        noMoreRecordsText: '<h2 style="text-align: center; padding-top: 20px; padding-bottom: 20px;">没有更多条记录了</h2>',
                        autoPaging: false //设置为TRUE将自动触发
                    }
                ]
            },
            {
                xtype: 'list',
                store: 'UnOrder',
                id: 'UnOrderSeachID',
                style: 'font-size:12px;',
                emptyText: '木有数据',
                hidden: true,
                pressedCls:false,
                selectedCls:false,
                cls:'x-list3',
                flex: 1,
                itemTpl: '<table class="tabclass">' +
                    '<tr>' +
                    '<td style="max-width: 20px;"><input type="checkbox" name="search_record" value="{coid}" /></td>' +
                    '<td>{consignee}</td>' +
                    '<td>{otel}</td>' +
                    '<td>{[Ext.Date.format(new Date(parseInt(values.createtime) * 1000), "Y-m-d H:i")]}<br>{takedate} {[values.taketime.substr(0,5)]}</td>' +
                    '<td>{takeaddress}</td>' +
                    '<td><tpl for="products"><p>{pname} / {sname}<br></p></tpl></td>' +
                    '<td>{totalmoney} ￥</td>' +
                    '<td>{paymenttype}<tpl if="paymenttype!=\'货到付款\' ">({paymentstatus})</tpl></td>' +
                    '<td><input type="button" value="详情" name="detail" /> &nbsp;&nbsp;<input type="button" value="处理" name="passorder" /></td>' +
                    '</tr>' +
                    '</table>'
            }
        ]
    }
});